/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package dgbgui.gui;

import java.awt.Color;
import java.util.Calendar;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JComponent;
import javax.swing.JEditorPane;

import dgbgui.logging.ErrorLogger;

/**
 * @author bjnortier
 * The ErrorInspector displays errors from the ErrorLogger 
 * in the error window
 */
public class ErrorInspector implements Observer {

    public ErrorInspector() {
        // Create the text area that will be used to display the 
        // error information
        m_textArea = new JEditorPane();
        m_textArea.setEditable(false);
        m_textArea.setForeground(Color.red);
    }

    // Update the inspector text area with the error string
    public void update(Observable source, Object data) {
       if ( source instanceof ErrorLogger ) {
           String error = (String)data;
           assert (error != null);
           Calendar now = Calendar.getInstance();
           String timeStamp = String.format(
                   "[%tT] - ",now);
           m_textArea.setText(
                   m_textArea.getText() + timeStamp + error + "\n");
       }
        
    }
    
    public JComponent getComponent() {
        return m_textArea;
    }
    
    JEditorPane m_textArea;
    
}
